package com.supreme.studyserver.controller;

import com.supreme.commonboot.utils.AjaxResp;
import com.supreme.studyserver.entity.Test;
import com.supreme.studyserver.service.JucQueueService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "juc.queue")
public class JucQueueController {

    @Resource
    private JucQueueService jucQueueService;

    @PostMapping(value = "putTest")
    public AjaxResp putTest(@RequestBody Test test) {
        jucQueueService.putTestQueue(test);
        return AjaxResp.instance();
    }

    @PostMapping(value = "takeTest")
    public AjaxResp takeTest() {
        final Test test = jucQueueService.takeTestQueue();
        return AjaxResp.instance(test);
    }

    @PostMapping(value = "putRunnableQueue")
    public AjaxResp putRunnableQueue() {
        jucQueueService.putRunnableQueue();
        return AjaxResp.instance();
    }

    @PostMapping(value = "takeRunnableQueue")
    public AjaxResp takeRunnableQueue() {
        jucQueueService.takeRunnableQueue();
        return AjaxResp.instance();
    }

    @PostMapping(value = "listenRunnableQueue")
    public AjaxResp listenRunnableQueue() {
        jucQueueService.listenRunnableQueue();
        return AjaxResp.instance();
    }
}
